package com.hbnu.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.entity.Team;
import com.hbnu.system.service.ITeamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/team")
@Api(tags = "科研团队模块")
public class TeamController {
    @Autowired
    ITeamService iTeamService;

    @ApiOperation("科研团队-录入")
    @PostMapping("/addTeam")
    public Rest<Boolean> addTeam(@RequestBody Team team){
        boolean add = iTeamService.addTeam(team);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研团队-删除")
    @GetMapping("/DeleteTeam")
    public Rest<Boolean> DeleteTeam(String teamID){
        boolean delete = iTeamService.deleteTeam(teamID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研团队-修改")
    @PostMapping("/updateTeam")
    public Rest<Boolean> updateTeam(@RequestBody Team team){
        boolean update = iTeamService.updateTeam(team);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键查询科研团队")
    @GetMapping("/GetTeamById")
    public Rest<Team> GetTeamById(String teamID){
        Team team = iTeamService.getTeamById(teamID);
        return Rest.success(team);
    }

    @ApiOperation("根据团队号查询科研团队")
    @GetMapping("/GetTeamByNum")
    public Rest<Team> GetTeamByNum(String teamNum){
        Team team = iTeamService.getTeamByTeamNum(teamNum);
        return Rest.success(team);
    }

    @ApiOperation("根据团队名称查询科研团队")
    @GetMapping("/GetTeamByName")
    public Rest<Team> GetTeamByName(String teamName){
        Team team = iTeamService.getTeamByTeamName(teamName);
        return Rest.success(team);
    }

    @ApiOperation("科研团队-分页")
    @PostMapping("/Pagecondition")
    public Rest<CommonPage<Team>> Pagecondition(@RequestBody SearchPageDTO searchPageDTO){
        IPage<Team> TeamIPage = iTeamService.pageCondition(searchPageDTO);
        CommonPage<Team> TeamCommonPage = CommonPage.restPage(TeamIPage);
        return Rest.success(TeamCommonPage);
    }

}

